package com.example.demo.web;

import com.example.demo.mapper.firstsqlserver.TodayRecordMapper;
import com.example.demo.pojo.TodayRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
public class TodayRecordController {

    @Autowired
    TodayRecordMapper mapper;

    @RequestMapping("/listTodayRecord")
    public String listRecord() {
        return "listTodayRecord";
    }

    @ResponseBody
    @RequestMapping("/listTodayRecordData")
    public List<TodayRecord> listData() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String startTime = sdf.format(new Date()) + " 00:00:00";
        String endTime = sdf.format(new Date()) + " 23:59:59";
        List<TodayRecord> cs = mapper.listRecord(startTime, endTime);
        //System.out.println("查询到的集合大小：" + cs.size());
        for (int i = 0; i < cs.size(); i++) {
            cs.get(i).setId(i + 1);
        }
        //m.addAttribute("cs", cs);
        return cs;
    }
}
